import e from "jquery";
import t from "./view";
import n from "./color";
import r from "./paths";

export default class Shape extends t {
  className = "AXEShape";
  dealloc() {
    let e = this;
    (e._paths = null),
      (e._strokeColor = null),
      (e._fillColor = null),
      t.prototype.dealloc.call(e);
  }
  clone() {
    let e = this,
      t = new Shape;
    return e.copyProperties(t), t;
  }
  copyProperties(e) {
    let n = this;
    t.prototype.copyProperties.call(n, e), // 等价于 super.copyProperties(e)
      e.strokeSize(n.strokeSize()),
      n.strokeColor() != null && e.strokeColor(n.strokeColor().clone()),
      n.fillColor() != null && e.fillColor(n.fillColor().clone()),
      n.paths() != null && (e._paths = n.paths().clone());
  }
  updatePropsFromXML(r) {
    let i = this;
    t.prototype.updatePropsFromXML.call(i, r),
      r.is("[stroke-size]") && i.strokeSize(parseFloat(r.attr("stroke-size"))),
      r.is("[stroke-color]") &&
        i.strokeColor(n.colorWithString(r.attr("stroke-color"))),
      r.is("[fill-color]") &&
        i.fillColor(n.colorWithString(r.attr("fill-color")));
    let s = r.find("> path");
    if (s.length > 0) {
      let o = e.trim(s.text());
      i.paths().clearCommands(), i.paths().addCommand(o);
    }
  }
  _strokeSize = 1;
  strokeSize(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        t._strokeSize != e &&
        ((t._strokeSize = e), t.needToRender(!0)),
      t._strokeSize
    );
  }
  _strokeColor = null;
  strokeColor(e?) {
    let t = this;
    return (
      arguments.length > 0 && ((t._strokeColor = e), t.needToRender(!0)),
      t._strokeColor
    );
  }
  _fillColor = null;
  fillColor(e?) {
    let t = this;
    return (
      arguments.length > 0 && ((t._fillColor = e), t.needToRender(!0)),
      t._fillColor
    );
  }
  _paths = null;
  paths() {
    let e = this;
    return (
      e._paths == null && ((e._paths = new r()), (e._paths.delegate = e)),
      e._paths
    );
  }
  onPathChanged(e) {
    let t = this;
    e == t.paths() && t.needToRender(!0);
  }
}
